﻿<UserControl x:Class="SoftSource.Timecard.Views.UserEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
             xmlns:softsourceConverters="clr-namespace:SoftSource.Common.Converters;assembly=SoftSource.Common.Silverlight"
             xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
             xmlns:converters="clr-namespace:SoftSource.Timecard.Converters">

    <UserControl.Resources>
        <softsourceConverters:ObjectToVisibilityConverter x:Name="ObjectToVisibilityConverter" />
        <softsourceConverters:EnumToDisplayNamePairConverter x:Key="EnumToDisplayNamePairConverter" />
        <softsourceConverters:EnumToDisplayNamePairCollectionConverter x:Key="EnumToDisplayNamePairCollectionConverter" />
        <converters:ObjectToManagerListConverter x:Key="ObjectToManagerListConverter" />
    </UserControl.Resources>

    <controlsToolkit:BusyIndicator x:Name="Busy"
                                   HorizontalContentAlignment="Stretch"
                                   VerticalContentAlignment="Stretch">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <dataform:DataForm x:Name="UserDataForm"
                               CurrentItem="{Binding User}"
                               AutoCommit="False"
                               AutoGenerateFields="False"
                               AutoEdit="True"
                               CommandButtonsVisibility="None">
                <dataform:DataForm.EditTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <dataform:DataField>
                                <TextBox Text="{Binding UserName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <TextBox Text="{Binding FullName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <TextBox Text="{Binding ExpectedHours, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <controls:DatePicker SelectedDate="{Binding StartDate, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <ComboBox DisplayMemberPath="TypeName"
                                          ItemsSource="{Binding Mode=OneWay, Source={StaticResource UserTypes}}"
                                          SelectedItem="{Binding UserTypeID, Converter={StaticResource UserTypeIDConverter}, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"
                                          Height="20"
                                          VerticalAlignment="Bottom" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <ComboBox DisplayMemberPath="Name"
                                          ItemsSource="{Binding Mode=OneWay, Source={StaticResource Roles}}"
                                          SelectedItem="{Binding RoleID, Converter={StaticResource RoleIDConverter}, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"
                                          Height="20"
                                          VerticalAlignment="Bottom" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <CheckBox IsChecked="{Binding IsAdministrative, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                            <dataform:DataField>
                                <TextBox Text="{Binding PTOHoursRolled, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" />
                            </dataform:DataField>
                        </StackPanel>
                    </DataTemplate>
                </dataform:DataForm.EditTemplate>
            </dataform:DataForm>

            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Button x:Name="SaveButton"
                        Grid.Column="0"
                        Content="Save"
                        Click="Save_Click"
                        Margin="4" />
                <Button x:Name="CancelButton"
                        Grid.Column="1"
                        Content="Cancel"
                        Click="Cancel_Click"
                        Margin="4" />
                <Button x:Name="EditProjectsButton"
                        Visibility="{Binding CreateUserProjectEditor, Converter={StaticResource ObjectToVisibilityConverter}}"
                        Grid.Column="2"
                        Content="Edit Projects"
                        Click="EditProjects_Click"
                        Margin="4" />
            </Grid>
        </Grid>
    </controlsToolkit:BusyIndicator>
</UserControl>